package tmsdkobf; import android.net.wifi.ScanResult; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.text.TextUtils; import com.miui.guardprovider.engine.mi.antivirus.NetworkApiHelper; import com.qq.taf.jce.JceStruct; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.json.JSONObject; import tmsdk.common.TMSDKContext; public class mg { /* renamed from: a reason: collision with root package name */ public static c f1498a; /* renamed from: b reason: collision with root package name */ public static long f1499b; static String c; /* access modifiers changed from: package-private */ public static class a implements t8 { /* renamed from: a reason: collision with root package name */ final /* synthetic */ c f1500a; /* renamed from: b reason: collision with root package name */ final /* synthetic */ String f1501b; final /* synthetic */ Object c; a(c cVar, String str, Object obj) { this.f1500a = cVar; this.f1501b = str; this.c = obj; } @Override // tmsdkobf.t8 public void onFinish(int i, int i2, int i3, int i4, JceStruct jceStruct) { if (!(i3 == 0 && i4 == 0) && this.f1500a == null) { mg.a(mg.f1498a); } if (this.f1500a != null) { mg.f1498a = null; mg.f1499b = 0; } if (i3 == 0 && i4 == 0) { mg.c = this.f1501b; } synchronized (this.c) { this.c.notify(); } } } /* access modifiers changed from: package-private */ public static class b implements t8 { /* renamed from: a reason: collision with root package name */ final /* synthetic */ Object f1502a; b(Object obj) { this.f1502a = obj; } @Override // tmsdkobf.t8 public void onFinish(int i, int i2, int i3, int i4, JceStruct jceStruct) { if (i3 == 0 && i4 == 0) { ag.a(mg.b()); } synchronized (this.f1502a) { this.f1502a.notify(); } } } /* access modifiers changed from: package-private */ public static class c { /* renamed from: a reason: collision with root package name */ public String f1503a = null; /* renamed from: b reason: collision with root package name */ public String f1504b = null; public int c = 0; public int d = -1; public int e = 3; int f = -1; int g = 0; c() { } } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r0v1, types: [java.lang.String] */ /* JADX WARNING: Removed duplicated region for block: B:31:0x0072 */ /* JADX WARNING: Unknown variable types count: 1 */ private static int a() { HttpURLConnection httpURLConnection = null; try { HttpURLConnection httpURLConnection2 = (HttpURLConnection) new URL("https://tools.3g.qq.com/wifi/cw.html").openConnection(); try { if (wi.a() < 8) { System.setProperty("http.keepAlive", "false"); } boolean z = false; httpURLConnection2.setUseCaches(false); httpURLConnection2.setRequestProperty("Pragma", "no-cache"); httpURLConnection2.setRequestProperty("Cache-Control", "no-cache"); httpURLConnection2.setInstanceFollowRedirects(false); httpURLConnection2.setRequestMethod(NetworkApiHelper.REQUEST_METHOD_GET); httpURLConnection2.setReadTimeout(30000); int responseCode = httpURLConnection2.getResponseCode(); if (responseCode == 200 || (responseCode >= 301 && responseCode <= 305)) { String headerField = httpURLConnection2.getHeaderField("Meri"); if (headerField == null || !headerField.equals("Meri")) { httpURLConnection = a("https://tools.3g.qq.com/wifi/cw.html", httpURLConnection2); } z = true; } if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } if (!z || httpURLConnection == null) { return (!z || httpURLConnection != null) ? 3 : 4; } return 1; } catch (Throwable unused) { httpURLConnection = httpURLConnection2; if (httpURLConnection != null) { } } } catch (Throwable unused2) { if (httpURLConnection != null) { httpURLConnection.disconnect(); } } } static int a(int i) { if (((WifiManager) TMSDKContext.getApplicaionContext().getApplicationContext().getSystemService("wifi")) == null) { return -1; } try { return WifiManager.calculateSignalLevel(i, 100) + 1; } catch (Throwable unused) { return -1; } } private static int a(ScanResult scanResult) { String str; if (scanResult == null || (str = scanResult.capabilities) == null) { return -1; } if (str.contains("WEP")) { return 1; } if (scanResult.capabilities.contains("PSK")) { return 2; } return scanResult.capabilities.contains("EAP") ? 3 : 0; } /* JADX WARNING: Missing exception handler attribute for start block: B:10:0x001e */ private static String a(InputStream inputStream) { BufferedReader bufferedReader; StringBuilder sb; bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); sb = new StringBuilder(); while (true) { try { String readLine = bufferedReader.readLine(); if (readLine != null) { sb.append(readLine); } } catch (IOException unknown) { bufferedReader.close(); return sb.toString(); } catch (Throwable th) { try { bufferedReader.close(); } catch (IOException unused) { } throw th; } try { bufferedReader.close(); } catch (IOException unused2) { } return sb.toString(); } } /* JADX WARNING: Code restructure failed: missing block: B:21:0x005b, code lost: if (r2 != null) goto L_0x0061; */ /* JADX WARNING: Code restructure failed: missing block: B:24:0x005f, code lost: if (0 != 0) goto L_0x0061; */ /* JADX WARNING: Code restructure failed: missing block: B:27:?, code lost: r2.close(); */ private static String a(String str, HttpURLConnection httpURLConnection) { String str2; InputStream inputStream = null; try { str2 = !new URL(str).getHost().equals(httpURLConnection.getURL().getHost()) ? httpURLConnection.getURL().toExternalForm() : null; if (str2 == null) { try { if (httpURLConnection.getHeaderField("Location") != null) { str2 = httpURLConnection.getHeaderField("Location"); } } catch (Throwable unused) { } } if (str2 == null && httpURLConnection.getHeaderField("Refresh") != null) { String[] split = httpURLConnection.getHeaderField("Refresh").split(";"); if (split.length == 2) { str2 = split[1].trim(); } } if (str2 == null && (inputStream = httpURLConnection.getInputStream()) != null) { str2 = b(inputStream); } } catch (Throwable unused2) { str2 = null; } return str2; } static synchronized void a(c cVar) { synchronized (mg.class) { try { JSONObject jSONObject = new JSONObject(); jSONObject.put("maincode", String.valueOf(5)); jSONObject.put("time", String.valueOf(System.currentTimeMillis())); jSONObject.put("bssid", cVar.f1504b); jSONObject.put("ssid", cVar.f1503a); jSONObject.put("reportWifiType", String.valueOf(cVar.c)); jSONObject.put("reportSecurityType", String.valueOf(cVar.d)); jSONObject.put("subType", String.valueOf(cVar.e)); jSONObject.put("wifiGradeLevel", String.valueOf(cVar.f)); jSONObject.put("remark", "https://tools.3g.qq.com/wifi/cw.html"); jSONObject.put("sessionkey", String.valueOf(-1)); jSONObject.put("connectsource", String.valueOf(4)); jSONObject.put("wifiType", String.valueOf(cVar.g)); ag.a(jSONObject.toString(), b(), 33); } catch (Throwable unused) { } } } static int b(int i) { WifiInfo connectionInfo = ((WifiManager) TMSDKContext.getApplicaionContext().getSystemService("wifi")).getConnectionInfo(); if (connectionInfo != null) { return WifiManager.calculateSignalLevel(connectionInfo.getRssi(), i); } return -1; } public static String b() { return TMSDKContext.getApplicaionContext().getFilesDir().getAbsolutePath() + File.separator + "d_" + String.valueOf(33); } private static String b(InputStream inputStream) { String a2 = a(inputStream); String[] strArr = {"http-equiv\\s*=\\s*[\"']*refresh[\"']*\\s*content\\s*=\\s*[\"']*[^;]*;\\s*url\\s*=\\s*[\"']*([^\"'\\s>]+)", "[^\\w](?:location.href\\s*=|location\\s*=|location.replace\\s*\\()\\s*[\"']*([^\"'>]+)", "<NextURL>([^<]+)", "\\s+action\\s*=\\s*[\"']*([^\"'>]+)[\"'>\\s]*.*submit", "<LoginURL>([^<]+)"}; int length = strArr.length; String str = null; for (int i = 0; i < length && str == null; i++) { Matcher matcher = Pattern.compile(strArr[i], 2).matcher(a2); while (matcher.find() && str == null) { str = matcher.group(matcher.groupCount()); if (str != null && !str.trim().toLowerCase().startsWith("http")) { str = null; } } } return str; } /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ /* JADX WARNING: Missing exception handler attribute for start block: B:37:0x01a8 */ public static synchronized void b(c cVar) { synchronized (mg.class) { try { if (si.b(TMSDKContext.getApplicaionContext())) { WifiInfo connectionInfo = ((WifiManager) TMSDKContext.getApplicaionContext().getSystemService("wifi")).getConnectionInfo(); if (connectionInfo == null) { g0 g0Var = new g0(2042, new ArrayList()); h0 h0Var = new h0(new HashMap()); h0Var.f1273b.put(1, "33"); h0Var.f1273b.put(2, "11,[currentWifi == null]"); g0Var.c.add(h0Var); ag.a(g0Var); return; } String bssid = connectionInfo.getBSSID(); if (TextUtils.isEmpty(c) || c.compareToIgnoreCase(bssid) != 0) { if (cVar == null) { f1498a = c(); f1499b = System.currentTimeMillis() / 1000; } if (f1498a == null) { f1499b = 0; return; } g0 g0Var2 = new g0(33, new ArrayList()); h0 h0Var2 = new h0(new HashMap()); h0Var2.f1273b.put(1, String.valueOf(5)); h0Var2.f1273b.put(2, String.valueOf(System.currentTimeMillis())); h0Var2.f1273b.put(3, f1498a.f1504b); h0Var2.f1273b.put(4, f1498a.f1503a); h0Var2.f1273b.put(5, String.valueOf(f1498a.c)); h0Var2.f1273b.put(6, String.valueOf(f1498a.d)); h0Var2.f1273b.put(7, String.valueOf(f1498a.e)); h0Var2.f1273b.put(8, String.valueOf(f1498a.f)); h0Var2.f1273b.put(9, "Meri"); h0Var2.f1273b.put(13, String.valueOf(-1)); h0Var2.f1273b.put(14, String.valueOf(4)); h0Var2.f1273b.put(15, String.valueOf(f1498a.g)); if (f1499b >= 0 && cVar != null) { h0Var2.f1273b.put(17, String.valueOf(f1499b)); } g0Var2.c.add(h0Var2); ya h = aa.h(); if (g0Var2.c.size() <= 0 || h == null) { g0 g0Var3 = new g0(2042, new ArrayList()); h0 h0Var3 = new h0(new HashMap()); h0Var3.f1273b.put(1, "33"); h0Var3.f1273b.put(2, "99,[no data]"); g0Var3.c.add(h0Var3); ag.a(g0Var3); } Object obj = new Object(); h.a(4060, g0Var2, (JceStruct) null, 0, new a(cVar, bssid, obj)); synchronized (obj) { obj.wait(); } } } } catch (Throwable th) { g0 g0Var4 = new g0(2042, new ArrayList()); h0 h0Var4 = new h0(new HashMap()); h0Var4.f1273b.put(1, "33"); Map<Integer, String> map = h0Var4.f1273b; map.put(2, "88,[" + th.getMessage() + "]"); g0Var4.c.add(h0Var4); ag.a(g0Var4); } } } static c c() { int i; if (!si.b(TMSDKContext.getApplicaionContext())) { return null; } WifiManager wifiManager = (WifiManager) TMSDKContext.getApplicaionContext().getSystemService("wifi"); WifiInfo connectionInfo = wifiManager.getConnectionInfo(); String bssid = connectionInfo.getBSSID(); String ssid = connectionInfo.getSSID(); if (TextUtils.isEmpty(ssid) || TextUtils.isEmpty(bssid)) { g0 g0Var = new g0(2042, new ArrayList()); h0 h0Var = new h0(new HashMap()); h0Var.f1273b.put(1, "33"); h0Var.f1273b.put(2, "22,[ssid or bssid empty]"); g0Var.c.add(h0Var); ag.a(g0Var); return null; } int a2 = a(); List<ScanResult> scanResults = wifiManager.getScanResults(); int i2 = -1; if (scanResults != null) { int i3 = -1; for (ScanResult scanResult : scanResults) { if (connectionInfo.getBSSID().compareTo(scanResult.BSSID) == 0) { i2 = a(scanResult); i3 = b(scanResult.level) + 1; } } i = i2; i2 = i3; } else { i = -1; } int a3 = a(i2); c cVar = new c(); cVar.f1504b = bssid; cVar.f1503a = ssid; cVar.c = 0; cVar.d = i; cVar.e = a2; cVar.f = a3; cVar.g = 0; return cVar; } /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ /* JADX WARNING: Missing exception handler attribute for start block: B:20:0x012f */ public static synchronized void d() { synchronized (mg.class) { try { ArrayList<String> c2 = ag.c(b()); if (c2 != null) { if (!c2.isEmpty()) { g0 g0Var = new g0(33, new ArrayList()); Iterator<String> it = c2.iterator(); while (it.hasNext()) { JSONObject jSONObject = new JSONObject(it.next()); h0 h0Var = new h0(new HashMap()); h0Var.f1273b.put(1, jSONObject.getString("maincode")); h0Var.f1273b.put(2, jSONObject.getString("time")); h0Var.f1273b.put(3, jSONObject.getString("bssid")); h0Var.f1273b.put(4, jSONObject.getString("ssid")); h0Var.f1273b.put(5, jSONObject.getString("reportWifiType")); h0Var.f1273b.put(6, jSONObject.getString("reportSecurityType")); h0Var.f1273b.put(7, jSONObject.getString("subType")); h0Var.f1273b.put(8, jSONObject.getString("wifiGradeLevel")); h0Var.f1273b.put(9, jSONObject.getString("remark")); h0Var.f1273b.put(13, jSONObject.getString("sessionkey")); h0Var.f1273b.put(14, jSONObject.getString("connectsource")); h0Var.f1273b.put(15, jSONObject.getString("wifiType")); g0Var.c.add(h0Var); } ya h = aa.h(); if (g0Var.c.size() > 0 && h != null) { Object obj = new Object(); h.a(4060, g0Var, (JceStruct) null, 0, new b(obj)); synchronized (obj) { obj.wait(); } } return; } } return; } catch (Throwable th) { g0 g0Var2 = new g0(2042, new ArrayList()); h0 h0Var2 = new h0(new HashMap()); h0Var2.f1273b.put(1, "33"); Map<Integer, String> map = h0Var2.f1273b; map.put(2, "88,[reportSaved::" + th.getMessage() + "]"); g0Var2.c.add(h0Var2); ag.a(g0Var2); } } } }